#ifndef MONITORINGREALDATA_H
#define MONITORINGREALDATA_H

#include <QWidget>
#include "MonitoringDataModel.h"
#include "deviceModel.h"
#include "MonitoringRealTabModel.h"
#include <QSerialPortInfo>
#include <QSerialPort>
#include "realDataThread.h"
#include "realWarnThread.h"
#include "MonitoringChart.h"
namespace Ui {
class MonitoringRealData;
}

class MonitoringRealData : public QWidget
{
    Q_OBJECT

public:
    explicit MonitoringRealData(QWidget *parent = nullptr,deviceModel*deviceModel=nullptr,userModel*userModel=nullptr);
    ~MonitoringRealData();
    void sendDataToServer(int&,int&,int&,int&,int&);
    void getJson(const QByteArray&);
    void sendData(int&,int&,int&,int&,int&);
    void sendWran(const QString&);
public slots:
    void openSerial();
    void onReadData();
    void handleDataReceived(const QByteArray &);
    void sendToData(int temperature,int humidity,int light,int co2,int pressure);
    void sendToWarn(int temperature,int humidity,int light,int co2,int pressure);
protected:
    void showEvent(QShowEvent *event) override;
private:
    Ui::MonitoringRealData *ui;
    deviceModel*dModel;
    userModel*uModel;
    QList<MonitoringDataModel> dataList;
    MonitoringRealTabModel tabModel;
    QTimer*timer;
    QSerialPort *m_port;
    bool isOpen;
    QString dev_id;
    bool isRole;
    int maxHemperature;
    int maxTemperature;
    int minHemperature;
    int minTemperature;
    realDataThread*p_dataThread;
    realWarnThread*p_warnThread;
    MonitoringChart*p_chart;
    QByteArray accumulatedData; // 用于存储拼接的数据
};

#endif // MONITORINGREALDATA_H
